//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.cqw.utils.data;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PIIDataAESEncoder {
    private final Logger logger = LoggerFactory.getLogger(PIIDataAESEncoder.class);
    private final AESEncoder aesEncoder;

    public PIIDataAESEncoder() {
        this.aesEncoder = new AESEncoder("cBXC1FyQ8//pCLfWhIFwpw==");
    }

    public String encode(String plainText) {
        return this.aesEncoder.encode(plainText);
    }

    public String decode(String encodedText) {
        try {
            return this.aesEncoder.decode(encodedText);
        } catch (Exception var3) {
            this.logger.warn("decode error. " + encodedText);
            return encodedText;
        }
    }

    public String decodeMobile(String encodedText) {
        String text = this.decode(encodedText);
        if (StringUtils.isBlank(text)) {
            return text;
        } else {
            return text.length() < 7 ? text : text.substring(0, 3).concat("****").concat(text.substring(7));
        }
    }

    public String decodePhone(String encodedText) {
        String text = this.decode(encodedText);
        if (StringUtils.isBlank(text)) {
            return text;
        } else {
            return text.length() < 8 ? text : text.substring(0, text.length() - 4).concat("****");
        }
    }

    public String decodeAddress(String encodedText) {
        String text = this.decode(encodedText);
        if (StringUtils.isBlank(text)) {
            return text;
        } else {
            return text.length() < 4 ? text : text.substring(0, 3).concat(StringUtils.leftPad("*", text.length() - 3, "*"));
        }
    }
}
